
function addformcopy()
{

   $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addCopyPlug featureclass">'+dataform['copy']+"</div>");
   var rownow=rowdiv;

    
  
  

   
   $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
   
   
    $('#feature'+rownow+' input[name="add"]').click(function(){
   

     
     addrowdatacopy(rownow);
    
   });
  
  
 
  
 
  
  
  
  
  
  
  
  
  
  
  
  //$('#feature'+rownow+' .group')
   
   
  
   

  
  
   rowdiv++;
}
function parseURL(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
}
 var  arraydataimg={}; 
function setimagecopydata(value2)
{

                                    arraydataimg={}; 
                                     
                                                             var  jqxhr2 =$.post(serviceinfo+'savelink', { url:value2.img.newpath }, function(data) { 
                                                             

                                                             arraydataimg['img']={};
                                                             arraydataimg['img']['newpath']=data.filelink;
                                                             arraydataimg['imgmid']=data.imgmid;
                                                             
                                                             
                                                             
                                                          
                                                             //  console.log('image1'); 
                                                             
                                                             });
                                                             
                                                             
                                                       return      jqxhr2 ;
                                                             
                                                          

}



function setimagecopydata2(value2)
{

                                                        
                                                             
                                                             
                                                                
var jqxhr3 =$.post(serviceinfo+'savelink', { url:value2.simg.newpath }, function(data) { 
                                                               

                           
                                                               
                                                               arraydataimg['simg']={};
                                                               arraydataimg['simg']['newpath']=data.filelink;
                                                               arraydataimg['simgmid']=data.imgmid;
                                                               arraydataimg['detail']=value2.detail;
                                                                                        
                                                               if(dataform[value2.plugname])
                                                                {
                                                                        var rowdatanow=value2;
                                                                       eval('editform'+value2.plugname+'(rowdatanow)');
                                                                       
                                                            //     console.log('image2');
                                                                  
                                                                }
                                                               
                                                               
});
                                                               
                                                               
return      jqxhr3;
                                                             
                                                             
                                                             
                                                             
                                                          
                                                             
                                                          

}

 $.ajaxSetup({ async: false });
function addrowdatacopy(rownow)
{
var copyurl=$('#feature'+rownow+' input[name="copyurl"]').val();
if(copyurl)
{


var dataparse=parseURL(copyurl);

if(dataparse['segments'][1])
{

var ajaxpath=dataparse['protocol']+'://'+dataparse['host']+'/ajax/getproduct';

$.get(ajaxpath, { productid:dataparse['segments'][1] }, function(data) {

if(data.data)
{
var valuedata=data.data[0];
$('#addform .featureclass') .remove();   
$('#firstaddform input[name="title"]').val(valuedata.title);
$('#firstaddform textarea[name="description"]').val(valuedata.description);

$("#lastaddform").html('');    
var arraydataimg={};    
var jqxhr2 =$.post(serviceinfo+'savelink', { url:valuedata.img.newpath }, function(data) {

arraydataimg['img']={};
arraydataimg['img']['newpath']=data.filelink;
arraydataimg['imgmid']=data.imgmid;

});
jqxhr2.done(function() {
   
   
                    $.post(serviceinfo+'savelink', { url:valuedata.simg.newpath }, function(data) { 

                     
                       arraydataimg['simg']={};
                       arraydataimg['simg']['newpath']=data.filelink;
                       arraydataimg['simgmid']=data.imgmid;
                       
                        editformthumbnail(arraydataimg);

                        if(valuedata.plugins.length)
                        {
                        
                        $.each(valuedata.plugins, function( index2, value2 ) {
                                                       
                                                       
                                                       
                                                       if(value2.plugname=='imagewidth'||value2.plugname=='image')
                                                       {
                                                            
                                                             var jshrx= setimagecopydata(value2);       
                                                             jshrx.done(function() {    
                                                             
                                                             
                                                                          var jshrx2=setimagecopydata2(value2);  
                                                                          
                                                                          jshrx2.done(function() {
                                                                          
                                                                         // console.log('function1'); 
                                                                          
                                                                          });
                                                             
                                                             
                                                             });
                                                       
                                                       }    
                                                       else if(value2.plugname=='vdoupload')
                                                       {
                                                              var jqxhr3 =$.post(serviceinfo+'iuploadfilemp4', { url:value2.file.newpath }, function(data) { 
                                                              
                                                              if(dataform[value2.plugname])
                                                                {
                                                                         arraydataimg={};
                                                                         arraydataimg['fileid']=data.fileid;
                                                                         arraydataimg['file']={};
                                                                         arraydataimg['file']['newpath']=data.filelink;
                                                                         var config={"allow":["mp4"],"accept":"video\/mp4"};
                                                                         editformvdoupload(config,arraydataimg);
                                                                }
                                                              
                                                              });
                                                              
                                                               jqxhr3.done(function() {
                                                                          
                                                                         // console.log('function1'); 
                                                                          
                                                                          });
                                                         
                                                       
                                                       } 
                                                       else if(value2.plugname=='comment')
                                                       {
                                                         
                                                         
                                                         if(dataform[value2.plugname])
                                                                {
                                                            //    console.log('function2'); 
                                                          var rowdatanow=value2;
                                                          $('.featurecommentcheck').remove();
                                                          eval('editform'+value2.plugname+'(rowdatanow)');
                                                                }
                                                         
                                                       
                                                       }
                                                       else
                                                       {
                                                             if(dataform[value2.plugname])
                                                                {
                                                          var rowdatanow=value2;

                                                          eval('editform'+value2.plugname+'(rowdatanow)');
                                                                }
                                                       
                                                       }
                            
                            
                            
                            });
                        
                        
                        }
                  

                  }); 
                  
                  
                  
         
   

                                    });

                                    


}



});


}else
{


}



}

}
function saveformcopy(id,plugid)
{

        var obj2=new Array();
        var krow=0;
       $("#"+id+' .choiQust' ).each(function( index ) {
       //console.log( index + ": " + $( this ).text() );
       
           obj2[krow]={typeid:1,pollfid:$(this).find('input[name="pollfid"]').val(),value:$(this).find('input[name="labeltxt"]').val()};
           krow++;
       
       });
       
       var obj3=new Array();
       var krow=0;
       $("#"+id+' input[name="deletepollfid"]' ).each(function( index ) {
       //console.log( index + ": " + $( this ).text() );
       
           obj3[krow]={pollfid:$(this).val()};
           krow++;
       
       });
       var otherdata=0;
       if($("#"+id+' input[name="otherpoll"]:checked').val())
       {
       otherdata=1;
       
       }
       
       
        var obj={plugid:plugid,title:$("#"+id+' input[name="questitle"]').val(),other:otherdata,userpoll:$("#"+id+' input[name="userpoll"]:checked').val(),spollid:$("#"+id+' input[name="spollid"]').val(),datarowobj:obj2,deleterowobj:obj3};
        
   //     console.log(obj);
    //    alert('');
        
       
        return obj;
}
function getformcopy(dataplugin)
{
var code='';
return code;

}



function editformcopy(datarow)
{
       addformcopy();

       var rownow= rowdiv-1;
  //
 //   }
       
      // $('#feature'+rownow+' input[name="questitle"]').val(datarow.title);
       //console.log(datarow.title);
       
       



}